package com.infore.exchange.main.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.infore.common.base.EppPage;
import com.infore.common.base.Msg;
import com.infore.common.base.ResultUtil;
import com.infore.common.base.WrapperHelp;
import com.infore.common.fw.BaseController;
import com.infore.common.model.entity.exchange.TTargetDataInfo;
import com.infore.common.model.entity.vo.exchange.TTargetDataInfoVo;
import com.infore.exchange.main.service.TTargetDataInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 数据同步-数据目标去向 前端控制器
 * </p>
 *
 * @author lijh
 * @since 2023-02-10
 */
@RestController
@Api(value = "数据同步-数据目标去向前端控制器", tags = "数据同步-数据目标去向前端控制器")
@RequestMapping("/tTargetDataInfo")
public class TTargetDataInfoController extends BaseController {
	private String prefix = "/tTargetDataInfo";

	@Autowired
	private TTargetDataInfoService TTargetDataInfoService;

	@GetMapping()
	public String TTargetDataInfoController(){
		return prefix;
	}

	/**
	 * 查询数据同步-数据目标去向列表
	 * @param ttargetdatainfoVo 数据同步-数据目标去向的vo类
	 * @return Msg<Object> 结果集
	 * @author lijh
	 * @since 2023-02-10
	 */
	@PostMapping("/list")
	@ResponseBody
	@ApiOperation(value = "查询数据同步-数据目标去向列表", notes = "数据同步-数据目标去向列表查询 ")
	public Msg<Object> list(TTargetDataInfoVo ttargetdatainfoVo){
		//sql查询条件
		Wrapper<TTargetDataInfo> wrapper = null ;
		try {
			wrapper = (Wrapper<TTargetDataInfo>) WrapperHelp.addCondition(new EntityWrapper<TTargetDataInfo>(), ttargetdatainfoVo);
		} catch (Exception e) {
			e.printStackTrace();
			return ResultUtil.error(500,e.getMessage());
		}
		//查询方法
		Page<TTargetDataInfo> eppPage = new EppPage<TTargetDataInfo>(TTargetDataInfoService,ttargetdatainfoVo,wrapper);
		return ResultUtil.successPage(TTargetDataInfoService.selectPage(eppPage, wrapper));
	}

	/**
	 * 查询数据同步-数据目标去向列表
	 * @param ttargetdatainfo 数据同步-数据目标去向
	 * @return Msg<Object> 结果集
	 * @author lijh
	 * @since 2023-02-10
	 */
	@ResponseBody
	@ApiOperation(value = "添加数据同步-数据目标去向", notes = "数据同步-数据目标去向新增")
	@RequestMapping(value="/add",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	public Msg<Object> add(@RequestBody TTargetDataInfo ttargetdatainfo){
		Wrapper<TTargetDataInfo> wrapper = new  EntityWrapper<TTargetDataInfo>();
	    wrapper.eq("1", "1");
		List<TTargetDataInfo> entityList = TTargetDataInfoService.selectList(wrapper);
		if(entityList.size()>0) {
			return ResultUtil.error("重复添加");
		}
	   //插入数据
		boolean flag = TTargetDataInfoService.insert(ttargetdatainfo);
		return ResultUtil.setResult(flag,ttargetdatainfo.getTargetId().toString());
	}


	/**
	  * 更新数据同步-数据目标去向方法
	  *
	  * @param ttargetdatainfo 数据同步-数据目标去向
	  * @return Msg<Object>
	  * @author lijh
	  * @since 2023-02-10
	  */
	@ResponseBody
	@ApiOperation(value = "更新数据同步-数据目标去向", notes = "数据同步-数据目标去向更新")
	@RequestMapping(value = "/edit", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public Msg<Object> edit(@RequestBody TTargetDataInfo ttargetdatainfo) {
		//插入数据
		boolean flag = TTargetDataInfoService.updateById(ttargetdatainfo);
		return ResultUtil.setResult(flag, ttargetdatainfo.getTargetId().toString());
	}

	/**
	 * 删除数据同步-数据目标去向
	 *
	 * @param  targetDataId
	 * @return Msg<Object>
	 * @author lijh
	 * @since 2023-02-10
	 */
	@RequestMapping(value = "/del", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "删除数据同步-数据目标去向", notes = "删除数据同步-数据目标去向")
	public Msg<Object> del(String targetDataId) {

		Map<String, Object> columnMap = new HashMap<String, Object>();
		columnMap.put("target_id", targetDataId);
		boolean flag = TTargetDataInfoService.deleteByMap(columnMap);
		return ResultUtil.setResult(flag);
	}
}
